home *** CD-ROM | disk | FTP | other *** search
- Path: scream.ing.com!news
- From: "John C. Lund" <jlund@allaire.com>
- Newsgroups: comp.lang.c++
- Subject: Delphi calling a C++ DLL; Help needed
- Date: Thu, 01 Feb 1996 11:05:17 -0600
- Organization: Allaire
- Message-ID: <3110F2CD.5287@allaire.com>
- NNTP-Posting-Host: 206.144.133.15
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6a (Win95; I)
-
- How can I use C++ DLLs to work with Delphi apps?
-
- I've written a simple Delphi program that calls a function in a C++ DLL
- I wrote. The DLL uses a "C" interface that I can call from other
- environments (like VB and C++). Although I can call the DLL function
- from my Delphi app, the parameters passed are garbage. I tried the same
- declarations I found in the Delphi libraries, but to no avail.
-
- For whatever reason it looks like the parameters are pushed and popped
- from the stack differently beween environments. I've tried declaring
- the function in Delphi with "stdcall", "cdecl", and "pascal".
-
- The parameters expected by the DLL are all LPSTR (i.e. char*), so I've
- tried passing PChar and an array of Char.
-
- Any suggestions?
-
-
- ***************
- Delphi SNIPPETS
- ***************
-
- {type, private}
- function GetFieldsForTable(
- pcharDataSourceName,
- pcharUsername,
- pcharPassword,
- pcharTableName: pChar
- ): integer;
-
- {implementation}
- function TODBCInformant.GetFieldsForTable;
- external 'patrik.dll' name 'GetFieldsForTable';
-
- {I call the function like this:}
- nIndex:= GetFieldsForTable(strpcopy(pcharBuiffer,'Test'),
- strpcopy(pcharBuiffer,''),
- strpcopy(pcharBuiffer,''),
- strpcopy(pcharBuiffer,'Employees'));
-
-
- ************
- C++ SNIPPETS
- ************
-
- // My C++ header (.H) declares the prototype like this:
- extern "C" INT FAR PASCAL EXPORT GetFieldsForTable(
- LPSTR lpszDataSourceName,
- LPSTR lpszUsername,
- LPSTR lpszPassword,
- LPSTR lpszTableName
- );
-
- /*
- My implementation uses the same format, and the function is named in the
- exports section of the .DEF file.
- */
-
-
- --
- // John C. Lund jlund@allaire.com http//:www.allaire.com/
-